using System;
using System.Collections.Generic;
using Microsoft.DirectX.Direct3D;
using Microsoft.Samples.DirectX.UtilityToolkit;
using TTDotNet.Util;

namespace TTDotNet.Engine.ThreeDEngine
{
    public class TextureCacher
    {
        private Dictionary<string, GameTexture> textures;

        public TextureCacher()
        {
            textures = new Dictionary<string, GameTexture>();
        }

        public GameTexture LoadTexture(string path)
        {
            if(textures.ContainsKey(path)) {
                return textures[path];
            }
            else {
                textures[path] = new GameTexture(path);
                return textures[path];
            }
        }
    }

    public class GameTexture
    {
        private string texturePath;
        private Texture texture;

        public GameTexture(string path)
        {
            this.texturePath = path;
            texture = TextureLoader.FromFile(Game.device, Utility.FindMediaFile(path));
        }

        public string FilePath
        {
            get { return texturePath; }
        }

        public Texture Texture
        {
            get { return texture; }
        }

        public int Width
        {
            get { return texture.GetLevelDescription(0).Width; }
        }

        public int Height
        {
            get { return texture.GetLevelDescription(0).Height; }
        }
    }
}
